import 'package:flutter/material.dart';
import 'package:gzx_dropdown_menu/gzx_dropdown_menu.dart';
import 'package:provider/provider.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBColor/YBColor.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/YBTextStyle/YBTextStyle.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBHelper/yb_chinese_text/yb_chinese_text.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBCityNameModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBJsonToModel/YBWorkTaiModel/YBMiShuTongListModel.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuProvider/YBMiShuTongProvider.dart';
import 'package:yb_zsyiji_androidflutter_pro/YBModule/YBWorkTaiModule/YBZhuanShuYingYongPage/YBMiShuTongPage/YBMiShuTongShangJiKuSubPage.dart';


class YBMiShuTongShangJiKuPage extends StatefulWidget {
  @override
  _YBMiShuTongShangJiKuPageState createState() => _YBMiShuTongShangJiKuPageState();
}

class _YBMiShuTongShangJiKuPageState extends State<YBMiShuTongShangJiKuPage> {

  GZXDropdownMenuController _dropdownMenuController = GZXDropdownMenuController();

  GlobalKey _stackKey = GlobalKey();

  String selectStr;

  String cityNameStr;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();

  }

  @override
  Widget build(BuildContext context) {


    return Container(
      child: Scaffold(
        appBar: AppBar(
          elevation: 0,
          title: Text(
            YBChineseText.workTaiShangJiKuTitle,
          ),
        ),
        body: MultiProvider(
          providers:[
            ChangeNotifierProvider(create:(context) => YBMiShuTongShangJuKuProvider()..getMiShuTongShangJuKuDataList(1,),),
            ChangeNotifierProvider(create: (context) => YBMiShuTongShangJiKuShaiXuanProvider()..getMiShuTongShangJuKuShaiXuan()),
          ],
          child: Stack(
            key: _stackKey,
            children: [
              Expanded(
                child: Column(
                  children: [
                    Container(
                      child:GZXDropDownHeader(
                        stackKey: _stackKey,
                        items: [
                          GZXDropDownHeaderItem(YBChineseText.homeTextAddress),
                          GZXDropDownHeaderItem(YBChineseText.workTaiAllShiWuTitle),
                        ],
                        borderColor: YBColor.white,
                        controller: _dropdownMenuController,
                        style:YBTextStyle.TextStyle18181812Medium,
                        dropDownStyle: YBTextStyle.TextStyle2D69E012Medium,
                      ),
                    ),
                    Expanded(
                      child: Container(
                        child: Consumer<YBMiShuTongShangJuKuProvider>(
                            builder:(context,dataList,child){
                              return SmartRefresher(
                                controller:dataList.easyfresh,
                                onRefresh: () async {
                                  dataList.getRefresh(null, null);
                                },
                                onLoading: () async {
                                  dataList.loadData(null, null);
                                },
                                enablePullUp: true,
                                enablePullDown: true,
                                child:CustomScrollView(
                                  slivers: [
                                    SliverList(
                                      delegate:SliverChildBuilderDelegate(
                                            (BuildContext context,int index){
                                          YBMiShuTongListModel listModel = dataList.shangJiKuModelList[index];
                                          print('----${dataList.shangJiKuModelList}');
                                          return YBMiShuTongShangJiKuSubPage(timeStr:listModel.createTime,addressStr: listModel.address,contentStr:listModel.requestTag,shengYuStr: listModel.maxGetOrderNumber.toString(),requestCode: listModel.requestCode,sysCode: listModel.sysCode,type: 1,);
                                        },childCount: dataList.shangJiKuModelList.length,
                                      ),
                                    ),
                                  ],
                                ),
                              );
                            }
                        ),
                      ),
                    ),
                  ],
                ),
              ),
              Container(
                child: Consumer<YBMiShuTongShangJiKuShaiXuanProvider>(
                   builder: (context,dataList,child){

                     return GZXDropDownMenu(
                       controller: _dropdownMenuController,
                       animationMilliseconds: 300,
                       dropdownMenuChanging: (isShow,index){

                       },
                       dropdownMenuChanged: (isShow,index){

                       },
                       menus: [
                         GZXDropdownMenuBuilder(dropDownWidget: _buildConditionListWidget(1,cityNameList: dataList.quanGuoCityNameList), dropDownHeight: YBTextStyle.adapterSize180),
                         GZXDropdownMenuBuilder(dropDownWidget: _buildConditionInfoListWidget(2,stringList: dataList.transcationList), dropDownHeight: YBTextStyle.adapterSize180),
                       ],
                     );
                   }
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  _buildConditionListWidget(int index,{List<YBCityNameModel> cityNameList,List<String> stringList}) {

    return ListView.separated(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: cityNameList.length,
      // item 的个数
      separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0),
      // 添加分割线
      itemBuilder: (BuildContext context, int index) {
        YBCityNameModel cityNameModel = cityNameList[index];
        return Container(
          child: InkWell(
            child: Container(
              height: YBTextStyle.adapterSize40,
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '${cityNameModel.provinceName}-${cityNameModel.cityName}-${cityNameModel.areaName}',
                    style: YBTextStyle.TextStyle64646414,
                  ),
                ),
              ),
            ),
            onTap: () async {
                setState(() {
                   cityNameStr = cityNameModel.cityName;
                   _dropdownMenuController.hide();
                });
            },
          ),
        );
      },
    );
  }

  _buildConditionInfoListWidget(int index,{List<YBCityNameModel> cityNameList,List<String> stringList}) {

    return ListView.separated(
      shrinkWrap: true,
      scrollDirection: Axis.vertical,
      itemCount: stringList.length,
      // item 的个数
      separatorBuilder: (BuildContext context, int index) => Divider(height: 1.0),
      // 添加分割线
      itemBuilder: (BuildContext context, int index) {
        String stringListModel = stringList[index];
        return Container(
          child: InkWell(
            child: Container(
              height: YBTextStyle.adapterSize40,
              child: Padding(
                padding: EdgeInsets.only(left: YBTextStyle.adapterSize20,right: YBTextStyle.adapterSize20),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Text(
                    '$stringListModel'??"",
                    style: YBTextStyle.TextStyle64646414,
                  ),
                ),
              ),
            ),
            onTap: () async {
              setState(() {
                selectStr = stringListModel;
                _dropdownMenuController.hide();
              });
            },
          ),
        );
      },
    );
  }
}

// Padding(
//   padding: EdgeInsets.only(left: 20,right: 20),
//   child: Row(
//     mainAxisAlignment: MainAxisAlignment.spaceBetween,
//     crossAxisAlignment: CrossAxisAlignment.center,
//     children: [
//       Container(
//         child: InkWell(
//           child: Row(
//             children: [
//               Container(
//                 child: Image.asset(YBImageStyle.getImagePath('lawyerImage_locationImageView')),
//               ),
//               Container(
//                 width: 3,
//               ),
//               Container(
//                 child: Text('全国',style: YBTextStyle.TextStyle18181812Medium,),
//               ),
//               Container(
//                 width: 3,
//               ),
//               Container(
//                 child: Image.asset(YBImageStyle.getImagePath('shopping_locationImage')),
//               ),
//             ],
//           ),
//           onTap: () async {
//
//           },
//         ),
//       ),
//       Container(
//         child:InkWell(
//           child: Row(
//             children: [
//               Container(
//                 child: Text(
//                   '全部事务',
//                   style: YBTextStyle.TextStyle18181812Medium,
//                 ),
//               ),
//               Container(
//                 width: 3,
//               ),
//               Container(
//                 child: Image.asset(YBImageStyle.getImagePath('shopping_locationImage')),
//               ),
//             ],
//           ),
//           onTap: () async {
//
//           },
//         ),
//       ),
//     ],
//   ),
// ),

//         SortCondition goodsSortCondition = items[index];
//         return GestureDetector(
//           onTap: () {
//             for (var value in items) {
//               value.isSelected = false;
//             }
//             goodsSortCondition.isSelected = true;
//
//             itemOnTap(goodsSortCondition);
//           },
//           child: Container(
// //            color: Colors.blue,
//             height: 40,
//             child: Row(
//               children: <Widget>[
//                 SizedBox(
//                   width: 16,
//                 ),
//                 Expanded(
//                   child: Text(
//                     goodsSortCondition.name,
//                     style: TextStyle(
//                       color: goodsSortCondition.isSelected ? Theme.of(context).primaryColor : Colors.black,
//                     ),
//                   ),
//                 ),
//                 goodsSortCondition.isSelected
//                     ? Icon(
//                   Icons.check,
//                   color: Theme.of(context).primaryColor,
//                   size: 16,
//                 )
//                     : SizedBox(),
//                 SizedBox(
//                   width: 16,
//                 ),
//               ],
//             ),
//           ),
//         );